package com.jsp.servlet;

import java.io.IOException;
import java.sql.SQLException;





import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.jsp.bean.AdminBean;
import com.jsp.service.AdminService;

public class AdminServlet extends HttpServlet {

private static final long serialVersionUID =1L;
	
	private AdminService adminService;
	private AdminBean admin;
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		this.doGet(request, response);
	}
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub

       request.setCharacterEncoding("UTF-8");
       response.setCharacterEncoding("UTF-8");

       try {
		adminlogin(request,response);
	} catch (SQLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	}
	private void adminlogin(HttpServletRequest request,
			HttpServletResponse response) throws SQLException, ServletException, IOException{
		// TODO Auto-generated method stub
		
		String adminName=request.getParameter("adminName");
		HttpSession session=request.getSession();//session
		session.setAttribute("adminName", adminName);//session
		String adminPassword=request.getParameter("adminPassword");
		adminService=new AdminService();
		admin=adminService.adminlogin(adminName,adminPassword);
		System.out.println("ad"+adminName);
		if(admin!=null){
			request.getRequestDispatcher("../admin/adminsuccess.jsp").forward(request,response);
			
		}else{
			request.getRequestDispatcher("../admin/adminerror.jsp").forward(request,response);
		}
	}
	;
	
}
